#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "socket_util.h"

int init_server() {
    //创建套接字
    int serv_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    //将套接字和IP、端口绑定
    struct sockaddr_in serv_addr;
    new_sockaddr(&serv_addr, "127.0.0.1", 12355);
    (void)bind(serv_sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr));

    //进入监听状态，等待用户发起请求
    listen(serv_sock, 20);

    return serv_sock;
}

int main(){
    int serv_sock = init_server();

    //向客户端发送数据
    struct room room;
    new_room(&room, serv_sock, 3);

    
    for (;play_new_round(&room);) {
        
    }

    destroy_room(&room);
    //关闭套接字
    close(serv_sock);

    return 0;
}